/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Link_panel.java
 *
 * Created on 22-05-2009, 19:23:10
 */
package VIEW;

import CONTROLLER.Controller;
import java.util.Observable;
import java.util.Observer;
import javax.swing.DefaultListModel;

/**
 *
 * @author Irene
 */
public class Link_panel extends javax.swing.JPanel implements Observer {

    private Controller ctrl;

    /** Creates new form Link_panel
     * @param ctrl controller
     */
    public Link_panel(Controller ctrl) {
        this.ctrl = ctrl;
        initComponents();
        ctrl.addObserver(this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        URLfield = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        titelField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        FunLinkList = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        WorkLinkList = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        ExerLinklList = new javax.swing.JList();
        jScrollPane4 = new javax.swing.JScrollPane();
        OtherLinkList = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        AddToFunButton = new javax.swing.JButton();
        AddToWorkButton = new javax.swing.JButton();
        AddToExerButton = new javax.swing.JButton();
        AddToOtherButton = new javax.swing.JButton();
        funRemoveButton = new javax.swing.JButton();
        WorkRemoveButton = new javax.swing.JButton();
        ExerRemoveButton = new javax.swing.JButton();
        OtheremoveButton = new javax.swing.JButton();
        clearButton = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText("Your Links");

        jLabel2.setText("URL:");

        jLabel3.setText("Title:");

        FunLinkList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(FunLinkList);

        WorkLinkList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(WorkLinkList);

        ExerLinklList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane3.setViewportView(ExerLinklList);

        OtherLinkList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane4.setViewportView(OtherLinkList);

        jLabel4.setText("Fun Links");

        jLabel5.setText("Work Links");

        jLabel6.setText("Exercise Links");

        jLabel7.setText("Other Links");

        AddToFunButton.setText("Add to");
        AddToFunButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddToFunButtonActionPerformed(evt);
            }
        });

        AddToWorkButton.setText("Add to");
        AddToWorkButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddToWorkButtonActionPerformed(evt);
            }
        });

        AddToExerButton.setText("Add to");
        AddToExerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddToExerButtonActionPerformed(evt);
            }
        });

        AddToOtherButton.setText("Add to");
        AddToOtherButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddToOtherButtonActionPerformed(evt);
            }
        });

        funRemoveButton.setText("Remove");
        funRemoveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                funRemoveButtonActionPerformed(evt);
            }
        });

        WorkRemoveButton.setText("Remove");
        WorkRemoveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                WorkRemoveButtonActionPerformed(evt);
            }
        });

        ExerRemoveButton.setText("Remove");
        ExerRemoveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExerRemoveButtonActionPerformed(evt);
            }
        });

        OtheremoveButton.setText("Remove");
        OtheremoveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OtheremoveButtonActionPerformed(evt);
            }
        });

        clearButton.setText("Clear");
        clearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(funRemoveButton)
                        .addGap(104, 104, 104)
                        .addComponent(WorkRemoveButton)
                        .addGap(113, 113, 113)
                        .addComponent(ExerRemoveButton)
                        .addGap(173, 173, 173)
                        .addComponent(OtheremoveButton))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(67, 67, 67)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(AddToFunButton)
                                    .addComponent(jLabel4))
                                .addGap(120, 120, 120)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(10, 10, 10)
                                        .addComponent(jLabel5))
                                    .addComponent(AddToWorkButton)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(36, 36, 36)
                                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(23, 23, 23)
                                        .addComponent(jLabel3)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(clearButton, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(URLfield, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                                    .addComponent(titelField))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(42, 42, 42)
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(76, 76, 76))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(81, 81, 81)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addComponent(AddToExerButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 161, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel7)
                                    .addComponent(AddToOtherButton))
                                .addGap(103, 103, 103)))))
                .addContainerGap(210, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel3)
                                    .addComponent(titelField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(URLfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(clearButton)
                                .addGap(34, 34, 34)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(AddToFunButton)
                                    .addComponent(AddToExerButton)))
                            .addComponent(AddToOtherButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7))
                        .addGap(11, 11, 11))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(AddToWorkButton)
                        .addGap(36, 36, 36)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(funRemoveButton)
                    .addComponent(WorkRemoveButton)
                    .addComponent(ExerRemoveButton)
                    .addComponent(OtheremoveButton))
                .addGap(155, 155, 155))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void AddToFunButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddToFunButtonActionPerformed
        ctrl.addFunLink(titelField.getText(), URLfield.getText());
    }//GEN-LAST:event_AddToFunButtonActionPerformed

    private void AddToWorkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddToWorkButtonActionPerformed
        ctrl.addWorkLink(titelField.getText(), URLfield.getText());
    }//GEN-LAST:event_AddToWorkButtonActionPerformed

    private void AddToExerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddToExerButtonActionPerformed
        ctrl.addFitnessLink(titelField.getText(), URLfield.getText());
    }//GEN-LAST:event_AddToExerButtonActionPerformed

    private void AddToOtherButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddToOtherButtonActionPerformed
        ctrl.addOtherLink(titelField.getText(), URLfield.getText());
    }//GEN-LAST:event_AddToOtherButtonActionPerformed

    private void funRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_funRemoveButtonActionPerformed
        String s = (String) FunLinkList.getSelectedValue();
        ctrl.removeFunLink(s);
    }//GEN-LAST:event_funRemoveButtonActionPerformed

    private void WorkRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WorkRemoveButtonActionPerformed
        String s = (String) WorkLinkList.getSelectedValue();
        ctrl.removeWorkLink(s);
    }//GEN-LAST:event_WorkRemoveButtonActionPerformed

    private void ExerRemoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExerRemoveButtonActionPerformed
        String s = (String) ExerLinklList.getSelectedValue();
        ctrl.removeFitnessLink(s);
    }//GEN-LAST:event_ExerRemoveButtonActionPerformed

    private void OtheremoveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OtheremoveButtonActionPerformed
        String s = (String) OtherLinkList.getSelectedValue();
        ctrl.removeOtherLink(s);
    }//GEN-LAST:event_OtheremoveButtonActionPerformed

    private void clearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearButtonActionPerformed
        titelField.setText("");
        URLfield.setText("");
    }//GEN-LAST:event_clearButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddToExerButton;
    private javax.swing.JButton AddToFunButton;
    private javax.swing.JButton AddToOtherButton;
    private javax.swing.JButton AddToWorkButton;
    private javax.swing.JList ExerLinklList;
    private javax.swing.JButton ExerRemoveButton;
    private javax.swing.JList FunLinkList;
    private javax.swing.JList OtherLinkList;
    private javax.swing.JButton OtheremoveButton;
    private javax.swing.JTextField URLfield;
    private javax.swing.JList WorkLinkList;
    private javax.swing.JButton WorkRemoveButton;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton funRemoveButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextField titelField;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
        updateLinks();
        System.out.println("link virker");
    }

    public void updateLinks() {
        DefaultListModel list = ctrl.getExerciseLinkList();
        ExerLinklList.setModel(list);
        DefaultListModel fList = ctrl.getFunLinkList();
        FunLinkList.setModel(fList);
        DefaultListModel wList = ctrl.getWorkLinkList();
        WorkLinkList.setModel(wList);
         DefaultListModel oList = ctrl.getOtherLinkList();
        OtherLinkList.setModel(oList);


        repaint();

    }
}